/**
 * clone仓库的方式
 */
const { promisify } = require("util");
const downloadGitRepo = require("download-git-repo"); // 可以根据项目名和tag 拉去仓库，不支持promise
const path = require("path");
const newDownloadGitRepo = promisify(downloadGitRepo);
const {log,bigText} = require('./welcome');
const { newSpawn } = require('./spawn');

async function clone1(repo, desc) {
  const repoUrl = "github:zfxj/reactDo#main";
  const ora = require("ora");
  const processLoading = ora("下载中，请稍后。。。");
  processLoading.start();
  let res = await newDownloadGitRepo(
    repoUrl,
    path.resolve(process.cwd(), `${"repoName"}@${"version"}`)
  );
  console.log(`res`, res);
  processLoading.succeed();
}

async function clone2(repo, desc) {
  const shell = require("shelljs");
  // const path = path.resolve(process.cwd(),`${'repoName'}@${'version'}`)
  // shell.cd(path)
  shell.exec(
    "git clone http://172.18.71.186/develope/developetraining/developercomponte/webgroup/webframe_2020/webframepc.git" // 公司自己搭建的私有库
  );
}

async function clone3(projectName, desc) {
    const ora = require("ora");
    let fileName = 'myapp'
    const processLoading = ora("下载中，请稍后。。。");
    await  newDownloadGitRepo(
    // "direct:https://github.com/zfxj/studyDemo.git#main",
    // 'direct:https://gitee.com/tuvdance/flutter_sys_log.git',// 互联网需要公有库
    'direct:http://172.18.71.186/develope/developetraining/developercomponte/webgroup/webframe_2020/webframepc.git', // 公司自己搭建的私有库
    path.resolve(process.cwd(),projectName),
    { clone: true }
  );
  processLoading.succeed();
  // 安装依赖
  log("🔨安装依赖")
  /**
   * {cwd:`./${fileName} 表示在此目录下运行npm install命令
   */
    processLoading.start("安装依赖中，请稍后。。。");
  await newSpawn('npm',['install'],{cwd:`./${projectName}`})
  await bigText('jun Welcome')
  log(`
  👌安装完成：
  To get Start:
  ===========================
  cd ${projectName}
  npm run dev
===========================
  `)
  processLoading.succeed();
  

// 自动启动
// processLoading.start("启动中，请稍后。。。");
// processLoading.succeed();
// await newSpawn('npm',['run','dev'],{cwd:`./${fileName}`})
}
module.exports = {
  clone1,
  clone2,
  clone3
};
